export default {
	formatDate(date) {
		var nDate = new Date()
		if (date != '') {
			date = date.substr(0, 18)
			date = date.replace(/T/g, ' ').replace(/-/g, '/')
			var nDate = new Date(date)
		}
		var month = nDate.getMonth() + 1
		var day = nDate.getDate()
		var h = nDate.getHours()
		var m = nDate.getMinutes()
		return month + '月' + day + '日 ' + h + ':' + m
	},
	getDateNow() {
		var nDate = new Date()
		var year = nDate.getFullYear()
		var month = (nDate.getMonth() + 1 + '').padStart(2, '0')
		var day = nDate.getDate()
		var h = nDate.getHours()
		var m = nDate.getMinutes()
		var ss = nDate.getSeconds()
		var ms = nDate.getMilliseconds()
		var tt = year + '-' + month + '-' + day + 'T' + h + ':' + m + ':' + ss + '.' + ms + '+08:00'
		return tt
	},
	// currentPage(reData, key) {
	// 	if (reData.indexOf("}")>-1) {
	// 		var pages = getCurrentPages()
	// 		// console.log(pages)
	// 		var len = pages.length
	// 		for (var i = 0; i < len; i++) {
	// 			var page = pages[i]
	// 			console.log(page.route)
	// 			if (page.route == 'pages/message/chat/chat') {
	// 				page.$vm.recvMsg(reData)
	// 			} else if (page.route == 'pages/message/groupChat/groupChat') {
	// 				page.$vm.recvMsg(reData)
	// 			} else if(page.route == 'pages/message/message') {
	// 				let data = JSON.parse(reData)
	// 				data.count = 1
	// 				page.$vm.recvMsg(data)
	// 			} else {
	// 				// 将最新消息存入storage
	// 				let data = JSON.parse(reData)
	// 				data.count = 1
	// 				let list = uni.getStorageSync(key);
	// 				if (list) {
	// 					list.push(data)
	// 				} else {
	// 					list = [data]
	// 				}
	// 				uni.setStorageSync(key, list);
	// 			}
	// 		}
	// 	}
	// },
	reduceData(data) {
		let res = data.reduce((res, item) => {
		    return {...res, [item.id]: item}
		}, {})
		return res
	},
	dataMap(key, index) {
		let data = uni.getStorageSync(key)
		// console.log(key+'：', data)
		return data[index]
	},
	compare(property, desc) {
		return function (a, b) {
			var value1 = a[property];
			var value2 = b[property];
			let Time1 = new Date(value1);
			let timestemp1 = Time1.getTime();
			let Time2 = new Date(value2);
			let timestemp2 = Time2.getTime();
			if (desc == true) {
				// 升序排列
				return timestemp1 - timestemp2;
			} else {
				// 降序排列
				return timestemp2 - timestemp1;
			}
		}
	}
}